<!doctype html>

<!--注意：引入thymeleaf的名称空间-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

  <style>
      body {
          margin: 10px auto;
          width: 60%;
      }
  </style>
</head>
<body>

<h2>变量表达式</h2>
<div><span th:text="${author}">author</span></div>
<div><span th:text="${book.author.name}">book.author.name</span></div>
<div><span th:text="${session.user}">session.user</span></div>
<div>
  <p>list-books1</p>
  <ul th:each="book:${books1}">
    <li th:text="${book}">books1-item</li>
  </ul>
</div>
<div>
  <p>list-books2</p>
  <ul th:each="book:${books2}">
    <li th:text="${book}">books2-item</li>
  </ul>
</div>

<hr>

<h2>选择(星号)表达式</h2>
<div th:object="${user}">
  <span th:text="*{name}">user.name</span>
</div>

<h2>文字国际化表达式</h2>

<h2>URL 表达式</h2>
<a th:href="@{/aaa}">aaa</a>
<a th:href="@{/aaa(name=${user.getOrDefault('nameT', 'alexz')})}">aaa?name</a>
<a th:href="@{/aaa/bbb}">bbb</a>
<a th:href="@{../test}">test</a>

<h2>表达式语法</h2>
<div><span th:text="${author + '-test'}">${author + '-test'}</span></div>
<div><span th:text="${12 + 3}">${12 + 3}</span></div>
<div><span th:text="${author == null}">${author == null}</span></div>
<div><span th:text="${flag}">${flag}</span></div>
<div><span th:text="${flag1 and flag2}">${flag1 and flag2}</span></div>
<div><span th:text="${flag1 and false}">${flag1 and false}</span></div>

<h2>常用th标签</h2>
<div th:id="${thId}"><span>test</span></div>
<form action="" th:object="${user1}">
  <input type="text" name="username" th:value="*{username}">
  <input type="password" name="password" th:value="*{password}">
  <input type="submit">
</form>
<div th:if="${flag1}">th:if="${flag1}"</div>
<div th:if="${flag2}">th:if="${flag2}"</div>

</body>
</html>
